package hn.cch.indicator;

import java.util.List;
import java.util.stream.Collectors;

public class Jensen implements Indicator {
    @Override
    public Double indicator(List<Return> R) {

        Double meanPortfolio = R.stream().collect(Collectors.averagingDouble(Return::getRp));
        Double meanBenchmark = R.stream().collect(Collectors.averagingDouble(Return::getRb));
        Double meanRiskFree = R.stream().collect(Collectors.averagingDouble(Return::getRf));

        Double beta = new Beta().indicator(R);

        Double jensen = meanPortfolio - meanRiskFree - beta * (meanBenchmark - meanRiskFree);
        return jensen;
    }
}
